package com.hzcx.app.simplechat;

import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.amap.api.location.AMapLocationClient;
import com.downloader.PRDownloader;
import com.downloader.PRDownloaderConfig;
import com.hzcx.app.simplechat.chat.ChatUtil;
import com.hzcx.app.simplechat.common.Common;
import com.hzcx.app.simplechat.util.log.LogUtils;
import com.shuyu.gsyvideoplayer.player.PlayerFactory;
import com.tencent.bugly.crashreport.CrashReport;

import org.litepal.LitePal;

import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.unit.Subunits;

public class MyApplication extends Application {

    private static Context context;

    @Override
    public void onCreate() {
        MultiDex.install(this);
        super.onCreate();
        context = this;

        // 初始化百分比库
        AutoSizeConfig.getInstance().getUnitsManager()
                .setSupportDP(false)
                .setSupportSP(false)
                .setSupportSubunits(Subunits.PT);

        // 日志初始化
        LogUtils.init();

        // 初始化litepal数据库
        LitePal.initialize(this);

        // 初始化环信
        ChatUtil.getInstance().init(this);

        // 初始化litepal数据库
        LitePal.initialize(this);

        // 初始化bugly
//        if (!BuildConfig.DEBUG) {
            CrashReport.initCrashReport(getApplicationContext(), Common.BUGLY_APP_ID, false);
//        }
        // 文件下载库初始化
        PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
                .setReadTimeout(30_000)
                .setConnectTimeout(30_000)
                .build();
        PRDownloader.initialize(getApplicationContext(),config);

        AMapLocationClient.updatePrivacyShow(getContext(), true, true);
        AMapLocationClient.updatePrivacyAgree(getContext(), true);

    }

    public static Context getContext() {
        return context;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
